package com.acargil.sudoku.model.algorithm.possibility;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import com.acargil.sudoku.model.structure.StandardCell;

public class StandardCellPossibility {

	public static final int MAX_NUMBER_OF_POSSIBLE_VALUE = StandardCell.VALUE_RANGE.length-1; // -1 since empty value is not counted
	
	private int previousValue;
	private Set<Integer> possibilities;
	
	public StandardCellPossibility(int value) {
		this.previousValue = value;
		this.possibilities = new HashSet<Integer>(MAX_NUMBER_OF_POSSIBLE_VALUE);
	}

	public int getPreviousValue() {
		return previousValue;
	}
	
	public boolean isValueChanged(int currentValue) {
		return currentValue != this.previousValue;
	}
	
	public boolean addPossibility(Integer possibility) {
		return possibilities.add(possibility);
	}

	public boolean addAllPossibilities(Collection<Integer> possibilities) {
		return possibilities.addAll(possibilities);
	}

	public boolean removePossibility(Integer possibility) {
		return possibilities.remove(possibility);
	}

	public boolean removeAllPossibilities(Collection<Integer> possibilities) {
		return possibilities.removeAll(possibilities);
	}
	
	public void clearAllPossibilities() {
		possibilities.clear();
	}

	public int sizeOfPossiblity() {
		return possibilities.size();
	}
	
	public int[] getPossibilityArray() {
		int[] posibilitySet = new int[this.possibilities.size()];
		int index = 0;
		
		for (Integer possibility : this.possibilities) {
			posibilitySet[index] = possibility;
			index++;
		}
		
		return posibilitySet;
	}
	
}
